package com.whu.UVAProtocol;

import lombok.ToString;

/**
 * @Description
 * @Author chengeng
 * @Date 2021/10/28 17:02
 **/
@ToString(exclude = "msgBody" )
public class UVAMessageProtocolType1_3 {
    //约定字符0x6868
    private short magicNumber;
    //地址域
    private byte addressProp;
    //控制域 D7:DIR;D6：DIV ;D5-D4:待定；D3-D0:操作码
    private byte controlProp;
    //帧计数器4（总包数（2）|序列号（2））可选 只有分包时用
    private byte[] divs;
    //数据长度
    private short msgBodyLen;
    //除去无人机位置、电量、时间戳的用户数据
    private byte[] msgBody;
    //流水号
    private char serialNum;
    //经度
    private double longitude;
    //纬度
    private double latitude;
    //高度
    private float height;
    //电量百分比
    private byte battery;
    //时间戳BCD码
    private byte[] timeStamp;
    //CRC16modbus检验码
    private short crcCheckNum;
    //共12个属性

    public UVAMessageProtocolType1_3() {
    }
    private UVAMessageProtocolType1_3(Builder builder){
        this.magicNumber = builder.magicNumber;
        this.addressProp = builder.addressProp;
        this.controlProp = builder.controlProp;
        this.divs = builder.divs;
        this.msgBodyLen = builder.msgBodyLen;
        this.msgBody = builder.msgBody;
        this.serialNum = builder.serialNum;
        this.longitude = builder.longitude;
        this.latitude = builder.latitude;
        this.height = builder.height;
        this.battery = builder.battery;
        this.timeStamp = builder.timeStamp;
        this.crcCheckNum = builder.crcCheckNum;
    }

    public UVAMessageProtocolType1_3(short magicNumber, byte addressProp, byte controlProp,
                                     byte[] divs, short msgBodyLen, byte[] msgBody, char serialNum,double longitude,
                                     double latitude, float height, byte battery, byte[] timeStamp, short crcCheckNum) {

        this.magicNumber = magicNumber;
        this.addressProp = addressProp;
        this.controlProp = controlProp;
        this.divs = divs;
        this.msgBodyLen = msgBodyLen;
        this.msgBody = msgBody;
        this.serialNum = serialNum;
        this.longitude = longitude;
        this.latitude = latitude;
        this.height = height;
        this.battery = battery;
        this.timeStamp = timeStamp;
        this.crcCheckNum = crcCheckNum;
    }

    public short getMagicNumber() {
        return magicNumber;
    }

    public void setMagicNumber(short magicNumber) {
        this.magicNumber = magicNumber;
    }

    public byte getAddressProp() {
        return addressProp;
    }

    public void setAddressProp(byte addressProp) {
        this.addressProp = addressProp;
    }

    public byte getControlProp() {
        return controlProp;
    }

    public void setControlProp(byte controlProp) {
        this.controlProp = controlProp;
    }

    public byte[] getDivs() {
        return divs;
    }

    public void setDivs(byte[] divs) {
        this.divs = divs;
    }

    public short getMsgBodyLen() {
        return msgBodyLen;
    }

    public void setMsgBodyLen(short msgBodyLen) {
        this.msgBodyLen = msgBodyLen;
    }

    public byte[] getMsgBody() {
        return msgBody;
    }

    public void setMsgBody(byte[] msgBody) {
        this.msgBody = msgBody;
    }

    public char getSerialNum() {
        return serialNum;
    }

    public void setSerialNum(char serialNum) {
        this.serialNum = serialNum;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public byte getBattery() {
        return battery;
    }

    public void setBattery(byte battery) {
        this.battery = battery;
    }

    public byte[] getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(byte[] timeStamp) {
        this.timeStamp = timeStamp;
    }

    public short getCrcCheckNum() {
        return crcCheckNum;
    }

    public void setCrcCheckNum(short crcCheckNum) {
        this.crcCheckNum = crcCheckNum;
    }



    //消息体构造器
    static class Builder{
        //约定字符
        private short magicNumber = 0x6868;
        //地址域
        private byte addressProp;
        //控制域 D7:DIR;D6：DIV ;D5-D4:待定；D3-D0:操作码
        private byte controlProp;
        //帧计数器
        private byte[] divs;
        //数据长度
        private short msgBodyLen;
        //除去无人机位置、电量、时间戳的用户数据
        private byte[] msgBody;
        private char serialNum;
        //经度
        private double longitude;
        //纬度
        private double latitude;
        //高度
        private float height;
        //电量百分比
        private byte battery;
        //时间戳BCD码
        private byte[] timeStamp;
        //CRC16modbus检验码
        private short crcCheckNum;

        public Builder setAddressProp(byte addressProp){
            this.addressProp =  addressProp;
            return this;
        }
        public Builder setControlProp(byte controlProp){
            this.controlProp = controlProp;
            return this;
        }
        public Builder setDivs(byte[] divs){
            this.divs = divs;
            return this;
        }
        public Builder setMsgBodyLen(short msgBodyLen){
            this.msgBodyLen = msgBodyLen;
            return this;
        }
        public Builder setMsgBody(byte[] msgBody){
            this.msgBody = msgBody;
            return this;
        }
        public Builder setLongitude(double longitude){
            this.longitude = longitude;
            return this;
        }
        public Builder setLatitude(double latitude){
            this.latitude = latitude;
            return this;
        }
        public Builder setHeight(float height){
            this.height = height;
            return this;
        }
        public Builder setBattery(byte battery){
            this.battery = battery;
            return this;
        }
        public Builder setTimeStamp(byte[] timeStamp){
            this.timeStamp = timeStamp;
            return this;
        }
        public Builder setCrcCheckNum(short crcCheckNum){
            this.crcCheckNum = crcCheckNum;
            return this;
        }
        public Builder setSerialNum(char serialNum){
            this.serialNum = serialNum;
            return this;
        }
        public UVAMessageProtocolType1_3 build(){
            return new UVAMessageProtocolType1_3(this);
        }
    }
}
